<?php 
class class_nguoimua extends database
{
	
	// //////////////////////////////// Đăng Ký tài khoản ////////////////////////////////////////////
	
	function KiemTraTonTaiUserName($tendangnhap)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'select* from nguoi_mua where Username=\''.$tendangnhap.'\'';	
		$this->setQuery($sql);
		$row = $this->loadOneRow();
		return $row;
	}
	
	function KiemTraTonTaiEmail($email)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'select* from nguoi_mua where Username is not NULL and Email=\''.$email.'\'';
		$this->setQuery($sql);
		$row = $this->loadOneRow();
		return $row;
	}
	
	function themmoi($tendangnhap,$matkhau,$email,$hoten,$diachi,$dienthoai,$gioitinh,$ngaysinh,$hinhanh)
	{
		$timezone  = 7;
		$ngaydangky = gmdate("Y/m/d H:i:s", time() + 3600*($timezone+date("I"))); 

		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'insert into nguoi_mua(Username, Password, Email, HoTen, DiaChi, DienThoai, GioiTinh, NgaySinh, HinhAnh, NgayDangKy) values("'.$tendangnhap.'","'.$matkhau.'","'.$email.'","'.$hoten.'","'.$diachi.'","'.$dienthoai.'",'.$gioitinh.',"'.$ngaysinh.'","'.$hinhanh.'","'.$ngaydangky.'")';
				
		$this->setQuery($sql);
		$kq = $this->Query();
		$manhomsv = mysql_insert_id();
		return $manhomsv;
	}
	
	// đăng nhập /////////////////////////////////////////////////////////////////////////////
	
	function kiemtraacc($user, $pass)
	{
		$pass = md5($pass);
		$sql = 'select * from nguoi_mua where Username=\''.$user.'\' and Password=\''.$pass.'\'';		
		$this->setQuery($sql);
		$row = $this->loadOneRow();
		return $row;
	}
	
	// quản lý tài khoản người mua /////////////////////////////////////////////////////////////////
	
	function Listnguoimua($start,$limit)
	{
		$this->setQuery('set names utf8');
		$this->Query();

		$sql = 'select *
				from nguoi_mua
				where Username is not NULL
				order by Username limit '.$start.','.$limit;

		$this->setQuery($sql);
		$table = $this->LoadAllRow();
		return $table;		
	}
	
	function CountListnguoimua()
	{
		$sql = 'select * 
				from nguoi_mua
				where Username is not NULL';

		$this->setQuery($sql);
		$table = $this->LoadAllRow();
		$num = count($table);
		return $num;
	}
	
	function xoa($ma)
	{
		$sql = 'update nguoi_mua
				set username = NULL,
					email = NULL
				where maso='.$ma;		
		$this->setQuery($sql);
		$rs = $this->Query();
		return $rs;
	}
	
	function UpdateTrangThaiByMaUser($mauser, $MaTrangThai)
	{
		$sql = 'update nguoi_mua
				set TrangThaiTaiKhoan = '.$MaTrangThai.'
				where maso='.$mauser;		
		$this->setQuery($sql);
		$rs = $this->Query();
		return $rs;
	}

}
?>